#ifndef DAP_SETTING_H
#define DAP_SETTING_H

#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"

#define DAP_SETTING_MAGIC (0xA5A5A5A5) // 魔数
typedef enum {
    PORT_MODE_GPIO = 0,       //IO模拟
    PORT_MODE_SPI = 1,        //SPI模拟
    PORT_MODE_DEDIC_GPIO = 2, //专用GPIO模拟
} PORT_Mode_t;

typedef struct {
    float vref;    //接给被调试芯片的电压
    bool power_on; //是否打开电源
    bool port_on;  //是否打开端口
} Setting_Power_t;

typedef enum {
    RESET_NRST = 0,     //硬件复位
    RESET_POR,          //电源复位
    RESET_ARM_SWD_SOFT, //软件复位
} Setting_ResetBit_t;

typedef struct {
    uint32_t magic; //魔数
    PORT_Mode_t swd_port_mode;//SWD端口模式
    PORT_Mode_t jtag_port_mode;//JTAG端口模式
    Setting_Power_t power;
    Setting_ResetBit_t reset; //这是一个Bitmap，用来存储多种设置，每一位的功能见Setting_ResetBit_t

} MdLink_DAP_Setting_t, *pMdLink_DAP_Setting_t;
// 关键修改：添加结构体类型 (ui_setting_t)
#define DAP_SETTING_DEFAULT()             \
    (MdLink_DAP_Setting_t)                \
    {                                     \
        .magic = DAP_SETTING_MAGIC,       \
        .jtag_port_mode = PORT_MODE_GPIO, \
        .swd_port_mode = PORT_MODE_GPIO,  \
        .power = {                        \
            .vref = 3.3,                  \
            .power_on = false,            \
            .port_on = false,             \
        },                                \
        .reset = RESET_ARM_SWD_SOFT,      \
    }


    
esp_err_t load_dap_setting(void);
esp_err_t set_dap_setting(pMdLink_DAP_Setting_t pDap_Setting, bool is_to_flash);
esp_err_t dap_setting_load_default(bool is_to_flash);
pMdLink_DAP_Setting_t get_dap_setting(void);
#endif //DAP_SETTING_H
